package leecode;

import java.util.HashSet;
import java.util.Set;

/**
 * 唯一摩尔斯密码词
 */
public class _804_uniqueMorseRepresentations {
	
	public static void main(String[] args) {
		_804_uniqueMorseRepresentations app = new _804_uniqueMorseRepresentations();
		System.out.println(app.uniqueMorseRepresentations(new String[] {"a"}));
		System.out.println(app.uniqueMorseRepresentations(new String[] {"gin", "zen", "gig", "msg"}));
	}
	
    public int uniqueMorseRepresentations(String[] words) {
    	// 0 a, 1 a, 25 z
    	String[] strs = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
    	Set<String> set = new HashSet<>();
		StringBuilder sb = new StringBuilder();
    	for (String s : words) {
    		sb.delete(0, sb.length());
    		for (int i = 0; i < s.length(); i++) {
    			char c = s.charAt(i);
    			int index = c - 'a';
    			sb.append(strs[index]);
			}
    		set.add(sb.toString());
		}
    	return set.size();
    }
}
